package com.kun.filter;

import java.io.IOException;
import java.util.List;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 判断前台是否登录
 * @author Administrator
 *
 */
public class IsLoginFilter implements Filter {
	
	public void destroy() {
	}

	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {
		HttpServletRequest req = (HttpServletRequest)request;
		HttpServletResponse res = (HttpServletResponse)response;
		String name = (String) req.getSession().getAttribute("customerName");
		//System.out.println(name);
		if(null!=name && !"".equals(name)){
			chain.doFilter(request,response);
		}else{
			res.sendRedirect("index.jsp");
		}		

	}

	public void init(FilterConfig arg0) throws ServletException {
	}

}
